#!/usr/bin/env perl
#
use 5.010;
use strict;
use Getopt::Long;
use File::Basename;
use XML::Simple;
use Data::Dumper;

Getopt::Long::Configure("bundling");
Getopt::Long::Configure("no_pass_through");

$Getopt::Long::ignorecase = 0;

my %opt = ();

sub usage
{
    say "usage: $0 -s src.xml -d dest.xml.";
}

sub read_xml
{
    my $xmlfile = shift(@_);

    my $xmldict = ();
    my $xmlref= XML::Simple->new(KeyAttr => "name", ForceArray => 1);
    
    my $xmldict = $xmlref->XMLin($xmlfile);
    say Dumper($xmlref);

    return $xmldict;
}

#main
if (!GetOptions(\%opt, qw(h|help s=s d=s))) 
{
    &usage();
    exit(-1);
}

my $src = $opt{'s'};
my $dst = $opt{'d'};

if(not defined($src) or not defined($dst))
{
    &usage();
    exit(-1);
}

if(not -e $src or not -e $dst)
{
    say "source xml or destination xml does not exit";
    exit(-1);
}

my $sxml = &read_xml($src);
my $dxml = &read_xml($dst);

my $xmlout = new XML::Simple();
my $xmlstr = XMLout($sxml, RootName => "resources", outputfile => "out.xml");

